// subPages/health/sugar/sugar.js
import * as echarts from '../../../ec-canvas/echarts';
var util =  require('../../../utils/healthUtil.js');
var navListJson = require('../../../data/navListJson');
var indexJson = require('../../../data/indexJson');
var recordJson = require('../../../data/recordJson');
let LineChart = null
let LineChart2 = null
let LineChart3 = null
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    ec: {
      // lazyLoad: true // 延迟加载
    },
    type: 2,
    ec2:{
      // lazyLoad: true // 延迟加载
    },
    ec3:{
      // lazyLoad: true // 延迟加载
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setDate()
  },

  //左选择日期
  leftDate:function(e){
    var that = this
    that.setData({
      date: util.leftDate(that.data.date,e.currentTarget.dataset.type)
    })
    that.getData(that.data.date)
  },

  //右选择日期
  rightDate:function(e){
    var that = this
    that.setData({
      date: util.rightDate(that.data.date,e.currentTarget.dataset.type)
    })
    that.getData(that.data.date)
  },

  //设置日期
  setDate:function(){
    var that = this
    let date = util.setTime7(new Date())
    let Y = date.split('-')
    that.setData({
      date: date,
      date1: util.setTime10(new Date()),
      dateStart: Y[0]- 3,
      dateEnd: date,
      navList: navListJson.dateNaveList,
    })
  },

  bindDateChange: function(e) {
    var that = this
    that.setData({
      date: e.detail.value,
    })
    that.getData(that.data.date)
  },

  //获得数据
  getData:function(date){
    var that = this
    wx.request({
      url: app.globalData.apiUrl +'/get_user_xuetang',
      data: {
        userid: app.globalData.userId,
        time: date,
        type: that.data.type //周
      },
      method: 'get',
      header: {
        'content-type': 'application/json' //默认值
      },
      success: function (res) {
        // console.log(res)
        if(res.data.code == '200'){
          that.processingOneData(res.data.data2);
          that.processingEchartData(res.data.data);
        }else{
          util.showModal('提示','数据异常')
          return;
        }
      },
      fail: function (res) {
        console.log("失败",res);
      }
    })
  },

  //处理最近一条数据
  processingOneData:function(list){
    var that = this
    if(list.length != 0){
      var sugarList = indexJson.bloodSugarList
      for(let i in list)
      {
        if(list[i].type == 1){
          sugarList[0].data = list[i].blood
        }
        if(list[i].type == 2){
          sugarList[1].data = list[i].blood
        }
        if(list[i].type == 3){
          sugarList[2].data = list[i].blood
        }
        if(list[i].type == 4){
          sugarList[3].data = list[i].blood
        }
        if(list[i].type == 5){
          sugarList[4].data = list[i].blood
        }
        if(list[i].type == 6){
          sugarList[5].data = list[i].blood
        }
      }
      // console.log(sugarList)
      that.setData({
        isData: true,
        createtime: list[0].date,
        dataList: sugarList,
      })
    }else{
      that.setData({
        isData: false,
        dataList: indexJson.bloodSugarList2,
        tipTxt: {
          tipTxt: '暂无测量数据',
          tipImg: '/resources/healthData/index/noData.png'
        }
      })
    }
  },

  //处理图表数据
  processingEchartData:function(list){
    var that = this
    if(list.length != 0){
      let beforeBreakfastList = []
      let afterBreakfastList = []
      let beforeLunchList = []
      let afterLunchList = []
      let beforeDinnerList = []
      let afterDinnerList = []
      let beforeBreakfastTimeList = []
      let afterBreakfastTimeList = []      
      let beforeLunchTimeList = []
      let afterLunchTimeList = []
      let beforeDinnerTimeList = []
      let afterDinnerTimeList = []
      let breakfastTimeList = []
      let lunchTimeList = []
      let dinnerTimeList = []
      if(list.one.length != 0 || list.two.length != 0){
        for(let i in list.one){
          beforeBreakfastList.push(list.one[i].blood)
          beforeBreakfastTimeList.push(list.one[i].date)
        }
        for(let i in list.two){
          afterBreakfastList.push(list.two[i].blood)
          afterBreakfastTimeList.push(list.two[i].date)
        }
        if(beforeBreakfastTimeList.length > afterBreakfastTimeList.length){
          breakfastTimeList = beforeBreakfastTimeList
        }else{
          breakfastTimeList = afterBreakfastTimeList
        }
        that.setData({
          isBreakfastData: true,
          beforeBreakfastList: beforeBreakfastList,
          afterBreakfastList: afterBreakfastList,
          breakfastTimeList: breakfastTimeList,
          beforeBreakfastTimeList: beforeBreakfastTimeList,
          afterBreakfastTimeList: afterBreakfastTimeList
        })
        that.linechartsComponnet = that.selectComponent('#mychartLine');
        LineChart = null
        that.getLineGraphData();
      }else{
        that.setData({
          isBreakfastData: false,
          tipTxt: {
            tipTxt: '暂无测量数据',
            tipImg: '/resources/healthData/index/noData.png'
          }
        })
      }
      if(list.three.length != 0 || list.four.length != 0){
        for(let i in list.three){
          beforeLunchList.push(list.three[i].blood)
          beforeLunchTimeList.push(list.three[i].date)
        }
        for(let i in list.four){
          afterLunchList.push(list.four[i].blood)
          afterLunchTimeList.push(list.four[i].date)
        }
        if(beforeLunchTimeList.length > afterLunchTimeList.length){
          lunchTimeList = beforeLunchTimeList
        }else{
          lunchTimeList = afterLunchTimeList
        }
        that.setData({
          isLunchData: true,
          beforeLunchList: beforeLunchList,
          afterLunchList: afterLunchList,
          lunchTimeList: lunchTimeList,
          beforeLunchTimeList: beforeLunchTimeList,
          afterLunchTimeList: afterLunchTimeList
        })
        that.linechartsComponnet2 = that.selectComponent('#mychartLine2');
        LineChart2 = null
        that.getLineGraphData2();
      }else{
        that.setData({
          isLunchData: false,
          tipTxt: {
            tipTxt: '暂无测量数据',
            tipImg: '/resources/healthData/index/noData.png'
          }
        })
      }
      if(list.five.length != 0 || list.six.length != 0){
        for(let i in list.five){
          beforeDinnerList.push(list.five[i].blood)
          beforeDinnerTimeList.push(list.five[i].date)
        }
        for(let i in list.six){
          afterDinnerList.push(list.six[i].blood)
          afterDinnerTimeList.push(list.six[i].date)
        }
        if(beforeDinnerTimeList.length > afterDinnerTimeList.length){
          dinnerTimeList = beforeDinnerTimeList
        }else{
          dinnerTimeList = afterDinnerTimeList
        }
        that.setData({
          isDinnerData: true,
          beforeDinnerList: beforeDinnerList,
          afterDinnerList: afterDinnerList,
          dinnerTimeList: dinnerTimeList,
          beforeDinnerTimeList: beforeDinnerTimeList,
          afterDinnerTimeList: afterDinnerTimeList
        })
        that.linechartsComponnet3 = that.selectComponent('#mychartLine3');
        LineChart3 = null
        that.getLineGraphData3();
      }else{
        that.setData({
          isDinnerData: false,
          tipTxt: {
            tipTxt: '暂无测量数据',
            tipImg: '/resources/healthData/index/noData.png'
          }
        })
      }
      that.setData({
        arrList : list
      })
    }
  },

  //获取异常信息
  getErroyData:function(type,time){
    var that = this
    var list = that.data.arrList
    if(type == 1){
      for(let i in list.one){
        if(time == list.one[i].date && list.one[i].content){
          that.setData({
            breakfastText: list.one[i].content,
            breakfastETime: time
          })
          return true          
        }
      }
    }
    if(type == 2){
      for(let i in list.two){
        if(time == list.two[i].date && list.two[i].content){
          that.setData({
            breakfastText: list.two[i].content,
            breakfastETime: time
          })
          return true
        }
      }
    }
    if(type == 3){
      for(let i in list.three){
        if(time == list.three[i].date && list.three[i].content){
          that.setData({
            lunchText: list.three[i].content,
            lunchETime: time
          })
          return true
        }
      }
    }
    if(type == 4){
      for(let i in list.four){
        if(time == list.four[i].date && list.four[i].content){
          that.setData({
            lunchText: list.four[i].content,
            lunchETime: time
          })
          return true
        }
      }
    }
    if(type == 5){
      for(let i in list.five){
        if(time == list.five[i].date && list.five[i].content){
          that.setData({
            dinnerText: list.five[i].content,
            dinnerETime: time
          })
          return true
        }
      }
    }
    if(type == 6){
      for(let i in list.six){
        if(time == list.six[i].date && list.six[i].content){
          that.setData({
            dinnerText: list.six[i].content,
            dinnerETime: time
          })
          return true
        }
      }
    }
    return false
  },

  //线图表
  getLineGraphData:function(){
    var that = this
    if (!LineChart){
      that.init_LineEcharts(); //初始化图表
    }else{
      that.setLineOption(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts: function () {
    var that = this
    that.linechartsComponnet.init((canvas, width, height) => {
      // 初始化图表
      LineChart = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption();
      LineChart.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[0].data"
        that.setData({
          breakfastTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(1,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      LineChart.on('click',{seriesIndex: 1},function(e){
        // console.log(e)
        var data = "dataList[1].data"        
        that.setData({
          breakfastTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(2,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart;
    });
  },

  setLineOption: function () {
    LineChart.clear();  // 清除
    LineChart.setOption(this.getLineOption());  //获取新数据
  },

  //设置折线图表
  getLineOption: function () {
    var that = this
    var start = 0
    if(util.dataZoom(that.data.breakfastTimeList) >= util.dataZoom(that.data.afterBreakfastTimeList)){
      start = util.dataZoom(that.data.breakfastTimeList)
    }else{
      start = util.dataZoom(that.data.afterBreakfastTimeList)
    }
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: [{ 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.breakfastTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime13(value) + '日'
          }
        }
      },
      {
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.afterBreakfastTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime13(value) + '日'
          }
        }
      }
    ],
      yAxis: {
        type: 'value',
        name: '早餐',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,24],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: start,
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'早餐前',
        type:'line',
        connectNulls: true,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#fff',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.beforeBreakfastList
      },{
        name:'早餐后',
        type:'line',
        xAxisIndex: 1,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#616161',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#616161',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(97,97,97,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.afterBreakfastList
      }]
    };
    LineChart.hideLoading()
    return option;
  },

  //线图表2
  getLineGraphData2:function(){
    var that = this
    if (!LineChart2){
      that.init_LineEcharts2(); //初始化图表
    }else{
      that.setLineOption2(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts2: function () {
    var that = this
    that.linechartsComponnet2.init((canvas, width, height) => {
      // 初始化图表
      LineChart2 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart2.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption2();
      LineChart2.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[2].data"
        that.setData({
          lunchTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(3,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      LineChart2.on('click',{seriesIndex: 1},function(e){
        // console.log(e)
        var data = "dataList[3].data"        
        that.setData({
          lunchTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(4,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart2;
    });
  },

  setLineOption2: function () {
    LineChart2.clear();  // 清除
    LineChart2.setOption(this.getLineOption2());  //获取新数据
  },

  //设置折线图表
  getLineOption2: function () {
    var that = this
    var start = 0
    if(util.dataZoom(that.data.beforeLunchTimeList) >= util.dataZoom(that.data.afterLunchTimeList)){
      start = util.dataZoom(that.data.beforeLunchTimeList)
    }else{
      start = util.dataZoom(that.data.afterLunchTimeList)
    }
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },        
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: [
        { 
          type: 'category',
          show:true,
          boundaryGap:true,
          data : that.data.beforeLunchTimeList,
          axisLine:{
            show:true,
            lineStyle:{
              color: 'white',
              width: 1,
            }
          },
          axisTick:{
            show:false
          },
          axisLabel:{
            show:true,
            color: 'white',
            interval: 0,
            formatter: '{value}',
            formatter:function(value){
              return util.setTime13(value) + '日'
            }
          }
        },
        { 
          type: 'category',
          show:true,
          boundaryGap:true,
          data : that.data.afterLunchTimeList,
          axisLine:{
            show:true,
            lineStyle:{
              color: 'white',
              width: 1,
            }
          },
          axisTick:{
            show:false
          },
          axisLabel:{
            show:true,
            color: 'white',
            interval: 0,
            formatter: '{value}',
            formatter:function(value){
              return util.setTime13(value) + '日'
            }
          }
        },
      ],
      yAxis: {
        type: 'value',
        name: '午餐',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,24],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: start,
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'午餐前',
        type:'line',
        connectNulls: true,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#fff',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.beforeLunchList
      },{
        name:'午餐后',
        type:'line',
        xAxisIndex: 1,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#616161',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#616161',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(97,97,97,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.afterLunchList
      }]
    };
    LineChart2.hideLoading()
    return option;
  },

  //线图表3
  getLineGraphData3:function(){
    var that = this
    if (!LineChart3){
      that.init_LineEcharts3(); //初始化图表
    }else{
      that.setLineOption3(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts3: function () {
    var that = this
    that.linechartsComponnet3.init((canvas, width, height) => {
      // 初始化图表
      LineChart3 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart3.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption3();
      LineChart3.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[4].data"
        that.setData({
          dinnerTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(5,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      LineChart3.on('click',{seriesIndex: 1},function(e){
        // console.log(e)
        var data = "dataList[5].data"        
        that.setData({
          dinnerTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(6,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart3;
    });
  },

  setLineOption3: function () {
    LineChart3.clear();  // 清除
    LineChart3.setOption(this.getLineOption3());  //获取新数据
  },

  //设置折线图表
  getLineOption3: function () {
    var that = this
    var start = 0
    if(util.dataZoom(that.data.beforeDinnerTimeList) >= util.dataZoom(that.data.afterDinnerTimeList)){
      start = util.dataZoom(that.data.beforeDinnerTimeList)
    }else{
      start = util.dataZoom(that.data.afterDinnerTimeList)
    }
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: [
        {
          type: 'category',
          show:true,
          boundaryGap:true,
          data : that.data.beforeDinnerTimeList,
          axisLine:{
            show:true,
            lineStyle:{
              color: 'white',
              width: 1,
            }
          },
          axisTick:{
            show:false
          },
          axisLabel:{
            show:true,
            color: 'white',
            interval: 0,
            formatter: '{value}',
            formatter:function(value){
              return util.setTime13(value) + '日'
            }
          },
        },{
          type: 'category',
          show:true,
          boundaryGap:true,
          data : that.data.afterDinnerTimeList,
          axisLine:{
            show:true,
            lineStyle:{
              color: 'white',
              width: 1,
            }
          },
          axisTick:{
            show:false
          },
          axisLabel:{
            show:true,
            color: 'white',
            interval: 0,
            formatter: '{value}',
            formatter:function(value){
              return util.setTime13(value) + '日'
            }
          },
        }
      ],
      yAxis: {
        type: 'value',
        name: '晚餐',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,24],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: start,
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'晚餐前',
        type:'line',
        connectNulls: true,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#fff',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.beforeDinnerList
      },{
        name:'晚餐后',
        type:'line',
        xAxisIndex: 1,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#616161',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#616161',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(97,97,97,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.afterDinnerList
      }]
    };
    LineChart3.hideLoading()
    return option;
  },

  //记录按钮
  recordBtn: function () {
    wx.navigateTo({
      url: '/subPages/healthData/recordSugar/record'
    })
  },

  //选择导航栏
  switchNav(event){
    var that = this
    var cur = event.currentTarget.dataset.current;      
    if (that.data.currentTab == cur) {
      return false;
    } else {
      that.setData({
          currentTab: cur
      })
      that.setEchartsData(cur);
    }
  },

  //给图表赋值
  setEchartsData:function(cur){
    var that = this
    switch (cur) {
      case 0:
        that.setData({
          type: 2
        })
        that.getData(that.data.date)
        break;
      case 1:
        that.setData({
          type: 1
        })
        that.getData(that.data.date1)
        break;
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData(this.data.date)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    LineChart = null
    LineChart2 = null
    LineChart3 = null
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    LineChart = null
    LineChart2 = null
    LineChart3 = null
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // return {
    //   title: 'PAPN体重管理',
    //   path: 'pages/index/index',
    //   success: function(res) {
    //     // res.shareTickets 
    //   },
    //   fail: function(res) {
    //       console.log(res)
    //   }
    // }
  }
})